package com.xctech.yace.util;

import org.apache.commons.lang.StringUtils;
import org.apache.flink.api.java.tuple.Tuple2;

public class SelectUtil {

//    public static void main(String[] args) {
//        String key = "op";
//        String body = "{\n" +
//                "    \"owner\":\"TRADE\",\n" +
//                "    \"op\":0,\n" +
//                "    \"optype\":\"INSERT\",\n" +
//                "    \"actseq\":\"2.196689\",\n" +
//                "    \"xid\":\"0x0004.004.00003b8b\",\n" +
//                "    \"op\":\"TINSTRUCTION\",\n" +
//                "    \"op\":\n" +
//                "    {\n" +
//                "        \"L_INDEX_DAILY_MODIFY\":\"1\",\n" +
//                "        \"L_DAILY_INSTRUCTION_NO\":\"209830\"\n" +
//                "    },\n" +
//                "    \"jstime\":\"1636707529929000\",\n" +
//                "    \"after\":\n" +
//                "    {\n" +
//                "        \"VC_MAC\":\"5EF3354B2442\",\n" +
//                "        \"L_BEGIN_TIME\":\"1\",\n" +
//                "        \"L_COMBITEMPLATE_ID\":\"0\",\n" +
//                "        \"C_APPROVE_STATUS\":\"2\",\n" +
//                "        \"L_INDEX_MODIFY_INSTRUCTION\":\"0\",\n" +
//                "        \"C_ARBI_TYPE\":\"0\",\n" +
//                "        \"L_END_TIME\":\"235959\",\n" +
//                "        \"L_INVEST_TIME\":\"0\",\n" +
//                "        \"L_INVEST_ADVISER\":\"0\",\n" +
//                "        \"C_SOURCE\":\"1\",\n" +
//                "        \"C_RISK_APPROVE_STATUS\":\"2\",\n" +
//                "        \"C_ENTRUST_RESTRICT\":\"2\",\n" +
//                "        \"C_TARGET_TYPE\":\"1\",\n" +
//                "        \"C_CANCEL_BRANCH_DEAL_STATUS\":\"0\",\n" +
//                "        \"C_BUSIN_CLASS\":\"1\",\n" +
//                "        \"VC_IP_ADDRESS\":\"192.168.0.17\",\n" +
//                "        \"L_INVEST_DATE\":\"0\",\n" +
//                "        \"L_END_DATE\":\"20210622\",\n" +
//                "        \"C_OPERATOR_ASSESS\":\"1\",\n" +
//                "        \"L_MODIFY_OPERATOR\":\"0\",\n" +
//                "        \"L_ARBI_SETS\":\"0\",\n" +
//                "        \"L_BUSIN_BEGIN_DATE\":\"20210622\",\n" +
//                "        \"C_INSTRUCTION_TYPE\":\"2\",\n" +
//                "        \"L_DEPT_ID\":\"0\",\n" +
//                "        \"L_DAILY_INSTRUCTION_NO\":\"209830\",\n" +
//                "        \"C_DEAL_EXECUTE_STATUS\":\"1\",\n" +
//                "        \"UPDATED_TIME\":\"2021-06-22 11:31:49.000001\",\n" +
//                "        \"EN_TARGET_BASE\":\"0\",\n" +
//                "        \"L_APPROVE_DATE\":\"0\",\n" +
//                "        \"L_BUSIN_END_DATE\":\"20210622\",\n" +
//                "        \"L_HG_BATCH_NO\":\"0\",\n" +
//                "        \"C_FAIR_TRADE\":\"1\",\n" +
//                "        \"L_INSIDER_TRADING_NO\":\"0\",\n" +
//                "        \"L_DISPENSE_DATE\":\"0\",\n" +
//                "        \"C_ETF_AUTO\":\"0\",\n" +
//                "        \"C_INSTRUCTION_LEVEL\":\"0\",\n" +
//                "        \"L_FIRST_SETTLE_DATE\":\"0\",\n" +
//                "        \"L_SCHEMA_ID\":\"0\",\n" +
//                "        \"L_DIRECT_OPERATOR\":\"99991000\",\n" +
//                "        \"D_DATETIME\":\"2021-06-22 11:31:49\",\n" +
//                "        \"C_BRANCH_DEAL_STATUS\":\"0\",\n" +
//                "        \"L_MODIFY_TIME\":\"0\",\n" +
//                "        \"L_TRADE_RIVAL_NO\":\"0\",\n" +
//                "        \"L_DISPENSE_OPERATOR\":\"0\",\n" +
//                "        \"C_PAPERY_APPROVE\":\"0\",\n" +
//                "        \"L_APPROVE_TIME\":\"0\",\n" +
//                "        \"L_ADVISE_ID\":\"0\",\n" +
//                "        \"L_DISPENSE_TIME\":\"0\",\n" +
//                "        \"L_VOUCHPLAN_SERIAL_NO\":\"0\",\n" +
//                "        \"L_APPROVE_BUSIN_DATE\":\"20210622\",\n" +
//                "        \"L_ORG_ID\":\"0\",\n" +
//                "        \"L_TOENTR_SETS\":\"0\",\n" +
//                "        \"L_MODIFY_DATE\":\"0\",\n" +
//                "        \"C_CANCEL_STATUS\":\"2\",\n" +
//                "        \"L_INDEX_DAILY_MODIFY\":\"1\",\n" +
//                "        \"L_BATCH_SERIAL_NO\":\"5532\",\n" +
//                "        \"C_ENTRUST_EXECUTE_STATUS\":\"1\",\n" +
//                "        \"C_POWER_TYPE\":\"2\",\n" +
//                "        \"C_LOCK_FLAG\":\"0\",\n" +
//                "        \"L_HG_DAYS\":\"0\",\n" +
//                "        \"L_GROUP_ID\":\"0\",\n" +
//                "        \"VC_TRADE_FLAG\":\"0000\",\n" +
//                "        \"L_CANCEL_OPERATOR\":\"0\",\n" +
//                "        \"L_BASECOMBI_ID\":\"2\",\n" +
//                "        \"C_INSTRUCTION_STATUS\":\"1\",\n" +
//                "        \"L_DIRECT_INSTEAD_OPERATOR\":\"99991000\",\n" +
//                "        \"C_CANCEL_BRANCH_STATUS\":\"0\",\n" +
//                "        \"EN_TARGET_VALUE\":\"17639\",\n" +
//                "        \"C_QUOTE_SIDE\":\"0\",\n" +
//                "        \"L_FUND_ID\":\"2\",\n" +
//                "        \"VC_VOLSERIAL_NO\":\"WXC2AB00ZCRA\",\n" +
//                "        \"C_ETF_MANUAL\":\"0\",\n" +
//                "        \"C_TRADE_AGENT_FLAG\":\"0\",\n" +
//                "        \"L_SETTLE_SPEED\":\"1\",\n" +
//                "        \"L_DEFAULT_OPERATOR\":\"0\",\n" +
//                "        \"C_QUOTE_TYPE\":\"0\",\n" +
//                "        \"L_DIRECT_DATE\":\"20210622\",\n" +
//                "        \"L_CANCEL_TIME\":\"0\",\n" +
//                "        \"C_TARGET_BASE\":\"1\",\n" +
//                "        \"L_CRMW_BATCH_SERIAL_NO\":\"0\",\n" +
//                "        \"L_INDEX_LAST_MODIFY\":\"0\",\n" +
//                "        \"C_DISPENSE_STATUS\":\"1\",\n" +
//                "        \"L_APPLY_NO\":\"0\",\n" +
//                "        \"L_DATE\":\"20210622\",\n" +
//                "        \"D_HEART_BEAT\":\"2021-06-22 11:31:49\",\n" +
//                "        \"L_CANCEL_DATE\":\"0\",\n" +
//                "        \"L_INSTRUCTION_NO\":\"0\",\n" +
//                "        \"L_SETTLE_LOCK_OPERATOR\":\"0\",\n" +
//                "        \"C_BRANCH_STATUS\":\"0\",\n" +
//                "        \"C_TREATYHG_FLAG\":\"0\",\n" +
//                "        \"L_FEEDBACK_STATUS\":\"0\",\n" +
//                "        \"C_PRICE_CONTROL_TYPE\":\"1\",\n" +
//                "        \"L_APPROVE_OPERATOR\":\"0\",\n" +
//                "        \"C_SEARCH_SOURCE\":\"0\",\n" +
//                "        \"C_SPECIAL_FLAG\":\"0\",\n" +
//                "        \"L_DIRECT_TIME\":\"113149\",\n" +
//                "        \"L_SECOND_SETTLE_DATE\":\"0\",\n" +
//                "        \"C_FLOW_APPROVE_STATUS\":\"2\",\n" +
//                "        \"C_EXEC_PHASE\":\"0\",\n" +
//                "        \"C_STOCK_TARGET_TYPE\":\"2\",\n" +
//                "        \"C_ADVISE_TYPE\":\"0\",\n" +
//                "        \"L_LIMIT_OPERATOR\":\"0\",\n" +
//                "        \"C_DEAL_EXECUTE_FLAG\":\"1\",\n" +
//                "        \"L_BEGIN_DATE\":\"20210622\",\n" +
//                "        \"VC_UNIQUE_INSTRUCTION_NO\":\"73768\",\n" +
//                "        \"L_OPERATOR_NO\":\"0\"\n" +
//                "    },\n" +
//                "    \"scntime\":1624332709,\n" +
//                "    \"rowid\":\"AAAINDAAFAAAr/IAAF\",\n" +
//                "    \"scn\":\"696796269\"\n" +
//                "}\n" +
//                "##########################################################\n";
//
//        Tuple2<Integer, Integer> tuple2 = selectKey("op", body, 2);
////        Tuple2<Integer, Integer> tuple2 = selectKey("op", "234op123op", 4);
//        System.out.println(tuple2);
//        System.out.println(body.substring(tuple2.f0,tuple2.f1));
//    }

    public static Tuple2<Integer,Integer> selectKey(String key,String body,Integer index){
        int i = StringUtils.indexOf(body, key, index);
        if(i == -1){
            return new Tuple2<>(0,0);
        }
        return new Tuple2<>(i,i+key.length());
    }
}
